package com.bjb.vr.common.service;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.bjb.vr.common.ao.SysTenantAo;
import com.bjb.vr.common.dto.OptArea;
import com.bjb.vr.common.mapper.OptAreaMapper;
import com.bjb.vr.common.vo.OptAreaVo;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * @author admin
 * @description 针对表【opt_area】的数据库操作Service实现
 * @createDate 2022-08-22 19:22:13
 */
@Service
public class OptAreaService extends ServiceImpl<OptAreaMapper, OptArea> {

    @Resource
    private OptAreaMapper optAreaMapper;

    /**
     * 查询客户地址--关联查询
     *
     * @param tenantAo
     * @return
     */
    public List<OptAreaVo> queryAddress(SysTenantAo tenantAo) {
        LambdaQueryWrapper<OptArea> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OptArea::getPId, tenantAo.getPid());
        List<OptArea> optAreas = optAreaMapper.selectList(queryWrapper);
        List<OptAreaVo> areaVos = new ArrayList<>();
        optAreas.stream().forEach(opt -> {
            OptAreaVo optAreaVo = new OptAreaVo();
            BeanUtils.copyProperties(opt, optAreaVo);
            areaVos.add(optAreaVo);
        });
        return areaVos;
    }
}




